package com.flyco.modules.oms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectList;
import com.flyco.modules.oms.entity.OmsOrderDiscountRecord;
import com.flyco.modules.oms.mapper.OmsOrderDiscountRecordMapper;
import com.flyco.modules.oms.service.IOmsOrderDiscountRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 订单折扣使用记录
 * @Author: flyco
 * @Date: 2024-04-12
 * @Version: V1.0
 */
@Service
public class OmsOrderDiscountRecordServiceImpl extends ServiceImpl<OmsOrderDiscountRecordMapper, OmsOrderDiscountRecord> implements IOmsOrderDiscountRecordService {

    @Autowired
    private OmsOrderDiscountRecordMapper discountRecordMapper;

    //根据订单id获取已使用的有效折扣记录
    @Override
    public OmsOrderDiscountRecord getByOrderId(String orderId) {
        LambdaQueryWrapper<OmsOrderDiscountRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OmsOrderDiscountRecord::getOrderId, orderId)
                .eq(OmsOrderDiscountRecord::getUseStatus, 1);

        return discountRecordMapper.selectList(wrapper).stream().findFirst().orElse(null);
    }
}
